<?php
class NewsFForm extends BaseFormAdmin{
	public function configure(){
		$enables = array(
				'1'	=> __('is_enabled_1', null, 'table_list'),
				'0'	=> __('is_enabled_0', null, 'table_list'),
		);
		$this->setWidgets(array(
				'cate_id'        => new sfWidgetFormDoctrineChoice(array('model' => 'NewsCates', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('NewsCates b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'),'multiple' => false, 'add_empty' => __('option_select', null, 'table_list'))),
				'title'       => new sfWidgetFormInputText(),
				'description' => new sfWidgetFormTextarea(),
				'photo_url'   => new sfWidgetFormInputText(),
				'content'     => new sfWidgetFormTextarea(),
				'related_id'  => new sfWidgetFormInputText(),
				'is_hot'	  		=> new sfWidgetFormChoice(array('choices'=>$enables,'expanded'=>true)),
				'is_promotion'	  	=> new sfWidgetFormChoice(array('choices'=>$enables,'expanded'=>true)),
				'is_readmax'		=> new sfWidgetFormChoice(array('choices'=>$enables,'expanded'=>true)),

				'tags'        => new sfWidgetFormInputText()
		));

		$this->setValidators(array(
				'cate_id'        => new sfValidatorDoctrineChoice(array('model' => 'NewsCates', 'query' => Doctrine_Query::create()->select('b.id, b.name')->from('NewsCates b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'), 'required' => true),array('required'=> 'input cate_id')),
				'title'       => new sfValidatorString(array('max_length' => 255, 'required' => false)),
				'description' => new sfValidatorString(array('required' => false)),
				'photo_url'   => new sfValidatorString(array('required' => false)),
				'content'     => new sfValidatorString(array('required' => false)),
				'related_id'  => new sfValidatorString(array('required' => false)),
				'is_hot'            => new sfValidatorChoice(array('choices'=>array('0','1'))),
				'is_promotion'      => new sfValidatorChoice(array('choices'=>array('0','1'))),
				'is_readmax'        => new sfValidatorChoice(array('choices'=>array('0','1'))),
				
				'tags'        => new sfValidatorString(array('required' => false))
		));
		parent::configure();
		
		$this->setDefault('is_hot', '0');
		$this->setDefault('is_promotion', '0');
		$this->setDefault('is_readmax', '0');
		/*
		 * Setting name of form
		*/
		$this->widgetSchema->setNameFormat('News[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
}
